package g11.testutil;

import static org.junit.Assert.assertNotNull;
import g11.dao.DrugDAO;
import g11.dao.DrugDAOImpl;
import g11.dao.EmployeeDAO;
import g11.dao.EmployeeDAOImpl;
import g11.dao.PatientAssignmentDAO;
import g11.dao.PatientAssignmentDAOImpl;
import g11.dao.PatientDAO;
import g11.dao.PatientDAOImpl;
import g11.dao.WorkForDAO;
import g11.dao.WorkForDAOImpl;
import g11.model.Drug;
import g11.model.Employee;
import g11.model.Patient;

import org.junit.Test;

public class initAppointment {

	@Test
	public void initEmployeePatientAndAppointment() throws Exception {
		// create doctor object
		Employee employee1 = new Employee();
		employee1.setUsername("penny");
		employee1.setPassword("1234");
		Byte type = 1;
		employee1.setType(type);
		employee1.setName("Penny Money");
		employee1.setDepartment("Surgery");
		employee1.setTitle("Surgery Doctor");
		Employee doctorBill = new Employee();
		doctorBill.setUsername("bill");
		doctorBill.setPassword("1234");
		doctorBill.setType(type);
		doctorBill.setName("Bill Gates");
		doctorBill.setDepartment("Inpatient");
		doctorBill.setTitle("Inpatient Doctor");
		// persistent doctor object
		EmployeeDAO employeeDao = new EmployeeDAOImpl();
		Integer employeeId1 = employeeDao.createEmployee(employee1);
		Employee doctorPenny = new Employee();
		doctorPenny = employeeDao.getEmployeeById(employeeId1);
		Integer employeeBillId = employeeDao.createEmployee(doctorBill);
		doctorBill = employeeDao.getEmployeeById(employeeBillId);
		assertNotNull(doctorPenny);
		assertNotNull(doctorBill);
		// create patient object
		Patient patientNancy = new Patient();
		patientNancy.setUsername("nancy");
		patientNancy.setName("Nancy Ken");
		patientNancy.setPassword("1234");
		Byte userType = 0;
		patientNancy.setType(userType);
		patientNancy.setPhone("519-888-8888");
		patientNancy.setAddress("77 Weber Street");
		patientNancy.setOhip("111");
		patientNancy.setSin("111");
		patientNancy.setCurrentHealth("Diabetes.");

		Patient patientHugo = new Patient();
		patientHugo.setUsername("hugo");
		patientHugo.setName("Hugo Boss");
		patientHugo.setPassword("1234");
		patientHugo.setType(userType);
		patientHugo.setPhone("226-111-1111");
		patientHugo.setAddress("11 King Street");
		patientHugo.setOhip("222");
		patientHugo.setSin("222");
		patientHugo.setCurrentHealth("Good");
		// persistent patient object
		PatientDAO patientDao = new PatientDAOImpl();
		Integer patientNancyId = patientDao.createPatient(patientNancy);
		patientNancy = patientDao.getPatientById(patientNancyId);
		Integer patientHugoId = patientDao.createPatient(patientHugo);
		patientHugo = patientDao.getPatientById(patientHugoId);
		assertNotNull(patientNancy);
		assertNotNull(patientHugo);
		// create staff object
		// create staff kevin
		Employee staffKevin = new Employee();
		staffKevin.setUsername("kevin");
		staffKevin.setPassword("1234");
		Byte staffType = 2;
		staffKevin.setType(staffType);
		staffKevin.setName("Kevin Klein");
		staffKevin.setDepartment("Surgery");
		staffKevin.setTitle("Surgery Nurse");
		// persist staff object
		// save to employee table
		Integer staffKevinId;
		staffKevinId = employeeDao.createEmployee(staffKevin);
		staffKevin = employeeDao.getEmployeeById(staffKevinId);
		assertNotNull(staffKevin);
		// define assigned relation
		WorkForDAO workForDao = new WorkForDAOImpl();
		workForDao.createWorkForRelation(doctorPenny, staffKevin);

		byte permission = 0;
		PatientAssignmentDAO pAssignDao = new PatientAssignmentDAOImpl();
		pAssignDao.CreatePatientAssignment(doctorPenny, patientNancy,
				permission);
		pAssignDao
				.CreatePatientAssignment(doctorPenny, patientHugo, permission);

		// create drug object 2
		Drug drugAdvil = new Drug();
		drugAdvil.setDrugName("Advil");
		Byte drugType = 1;
		drugAdvil.setType(type);

		Drug drugTylenol = new Drug();
		drugTylenol.setDrugName("Tylenol");
		drugTylenol.setType(type);

		// persist durgs, get two persisted drug objects: drugAdvil, drugTylenol
		DrugDAO drugDao = new DrugDAOImpl();
		Integer drugAdvilId = drugDao.createDrug(drugAdvil);
		Integer drugTylenolId = drugDao.createDrug(drugTylenol);
		drugAdvil = drugDao.getDrugById(drugAdvilId);
		drugTylenol = drugDao.getDrugById(drugTylenolId);
		assertNotNull(drugAdvil);
		assertNotNull(drugTylenol);

	}

}
